1 Imports System.Data.OleDb
2 Public Class Main_Form
3     Dim ConnString As String =
"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=CLInventory.accdb; Persist Security Info=False"
4     Dim OleDbConn As OleDbConnection = New OleDbConnection(ConnString)
5     Dim myCommand
6     Dim MyReader
7     Dim str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, str12, str13, str14, str15 As String
8
9     Private Sub RegisterNewProductToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RegisterNewProductToolStripMenuItem.Click
10         Reg_Item.ShowDialog()
11     End Sub
12
13     Private Sub Main_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
14         Timer1.Enabled = True
15         Timer2.Enabled = True
16         Panel4.Visible = False
17         refreshing_utility()
18     End Sub
19
20     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
21
22         Dim mss As String
23         If ListView2.SelectedIndices.Count <=
0 Then
24             Return
25         End If
26         Dim itemNo As Integer = ListView2.SelectedIndices(
0)
27         Try
28             mss = MsgBox(
"Are you sure you want to Returned this Item?", MsgBoxStyle.YesNo)
29
30             If mss = System.Windows.Forms.DialogResult.No Then
31                 MsgBox(
"Returned is Cancel", MsgBoxStyle.Information, "Returned Failed!")
32                 Exit Sub
33             Else
34                 Try
35                     OleDbConn.Open()
36                     Dim CMD2 As New OleDb.OleDbCommand(
"DELETE FROM List_of_Barrowed WHERE ID=" & ListView2.Items(itemNo).SubItems(0).Text, OleDbConn)
37                     CMD2.ExecuteNonQuery()
38                     MsgBox(
"Items Successfully Returned")
39                 Catch ex As Exception
40                     MsgBox(ex.Message)
41                 End Try
42
43             End If
44
45         Catch ex As Exception
46             MsgBox(ex.Message)
47         Finally
48             OleDbConn.Close()
49         End Try
50         TextBox8.Text = TextBox5.Text + +TextBox6.Text
51         savetoreturned()
52         editing()
53         savealltrans()
54         refreshing_utility()
55     End Sub
56     Sub editing()
57         Dim id As String = Trim(TextBox7.Text)
58         Try
59             OleDbConn.Open()
60             Dim cmd2 As New OleDb.OleDbCommand(
"UPDATE Item_list SET No_of_Item=M0 WHERE (ID=M1)", OleDbConn)
61             cmd2.Parameters.AddWithValue(
"M0", TextBox8.Text)
62             cmd2.Parameters.AddWithValue(
"M1", id)
63             cmd2.ExecuteNonQuery()
64
65         Catch ex As Exception
66             MsgBox(ex.Message)
67         Finally
68             OleDbConn.Close()
69         End Try
70     End Sub
71     Sub savetoreturned()
72         Try
73
74             Dim OleDbConn As OleDbConnection = New OleDbConnection(ConnString)
75             OleDbConn.Open()
76
77             Dim MyOledbCommand As OleDbCommand = New OleDbCommand()
78             Dim itemNo As Integer = ListView2.SelectedIndices(
0)
79             MyOledbCommand.CommandText =
"Insert Into List_of_Returned " & "(Name_of_Student_,Department_,Position_,Name_of_Items_,No_of_Items_,Date_Time_) " _
80             & 
"Values (" _
81             & 
"'" & TextBox1.Text & "', " _
82               & 
"'" & TextBox2.Text & "', " _
83                 & 
"'" & TextBox3.Text & "', " _
84                   & 
"'" & TextBox4.Text & "', " _
85                     & 
"'" & TextBox5.Text & "', " _
86                     & 
"'" & Label6.Text & ", " & Label7.Text & "')"
87
88             MyOledbCommand.Connection = OleDbConn
89             MyOledbCommand.ExecuteNonQuery()
90             OleDbConn.Close()
91
92         Catch err As System.Exception
93
94         End Try
95         refreshing_utility()
96     End Sub
97
98     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
99         Label6.Text = TimeOfDay
100     End Sub
101     Sub refreshing_utility()
102         Try
103             Dim sql As String
104             sql =
"SELECT * FROM Item_list"
105             Dim ds As DataSet
106             ds = New DataSet
107
108             OleDbConn.Open()
109
110             Dim OdAP As OleDbDataAdapter
111             OdAP = New OleDbDataAdapter(sql, OleDbConn)
112             OdAP.Fill(ds)
113             ListView1.Items.Clear()
114             ListView1.Columns.Clear()
115             ListView1.GridLines = True
116             ListView1.FullRowSelect = True
117             ListView1.HideSelection = False
118             ListView1.MultiSelect = False
119
120
121
122             ListView1.Columns.Add(ds.Tables(
0).Columns(0).Caption, 30, HorizontalAlignment.Left)
123             ListView1.Columns.Add(ds.Tables(
0).Columns(1).Caption, 90, HorizontalAlignment.Left)
124             ListView1.Columns.Add(ds.Tables(
0).Columns(2).Caption, 90, HorizontalAlignment.Left)
125
126
127
128             Dim i As Integer
129             Dim icol As Integer = ds.Tables(
0).Columns.Count
130             Dim k As Integer
131             Dim krow As Integer = ds.Tables(
0).Rows.Count
132             Dim thisrow(icol) As String
133             Dim j As Integer =
1
134             For k =
0 To krow - 1
135                 For i =
0 To icol - 1
136                     thisrow(i) = ds.Tables(
0).Rows(k).Item(i).ToString
137                 Next
138                 Dim lsvi As New ListViewItem(thisrow,
0)
139                 If k /
2 <> Int(k / 2) Then
140                     lsvi.BackColor = Color.Lavender
141                 Else
142                     lsvi.BackColor = Color.White
143                 End If
144                 j = j +
1
145                 ListView1.Items.Add(lsvi)
146
147             Next
148             ListView1.Sort()
149         Catch exc As Exception
150             MsgBox(exc.Message)
151
152         Finally
153             OleDbConn.Close()
154         End Try
155         
''''''''''''''''''''''''''FOR Barrowed Items'''''''''''''''''
156         Try
157             Dim sql As String
158             sql =
"SELECT * FROM List_of_Barrowed"
159             Dim ds As DataSet
160             ds = New DataSet
161
162             OleDbConn.Open()
163
164             Dim OdAP As OleDbDataAdapter
165             OdAP = New OleDbDataAdapter(sql, OleDbConn)
166             OdAP.Fill(ds)
167             ListView2.Items.Clear()
168             ListView2.Columns.Clear()
169             ListView2.GridLines = True
170             ListView2.FullRowSelect = True
171             ListView2.HideSelection = False
172             ListView2.MultiSelect = False
173
174
175             ListView2.Columns.Add(ds.Tables(
0).Columns(0).Caption, 30, HorizontalAlignment.Left)
176             ListView2.Columns.Add(ds.Tables(
0).Columns(1).Caption, 90, HorizontalAlignment.Left)
177             ListView2.Columns.Add(ds.Tables(
0).Columns(2).Caption, 90, HorizontalAlignment.Left)
178             ListView2.Columns.Add(ds.Tables(
0).Columns(3).Caption, 90, HorizontalAlignment.Left)
179             ListView2.Columns.Add(ds.Tables(
0).Columns(4).Caption, 90, HorizontalAlignment.Left)
180             ListView2.Columns.Add(ds.Tables(
0).Columns(5).Caption, 90, HorizontalAlignment.Left)
181             ListView2.Columns.Add(ds.Tables(
0).Columns(6).Caption, 130, HorizontalAlignment.Left)
182
183             Dim i As Integer
184             Dim icol As Integer = ds.Tables(
0).Columns.Count
185             Dim k As Integer
186             Dim krow As Integer = ds.Tables(
0).Rows.Count
187             Dim thisrow(icol) As String
188             Dim j As Integer =
1
189             For k =
0 To krow - 1
190                 For i =
0 To icol - 1
191                     thisrow(i) = ds.Tables(
0).Rows(k).Item(i).ToString
192                 Next
193                 Dim lsvi As New ListViewItem(thisrow,
0)
194                 If k /
2 <> Int(k / 2) Then
195                     lsvi.BackColor = Color.Lavender
196                 Else
197                     lsvi.BackColor = Color.White
198                 End If
199                 j = j +
1
200                 ListView2.Items.Add(lsvi)
201
202             Next
203             ListView2.Sort()
204         Catch exc As Exception
205             MsgBox(exc.Message)
206
207         Finally
208             OleDbConn.Close()
209         End Try
210         
''''''''''''''''''''' FOR RETURNED ITEM''''''''''''''
211         Try
212             Dim sql As String
213             sql =
"SELECT * FROM List_of_Returned"
214             Dim ds As DataSet
215             ds = New DataSet
216
217             OleDbConn.Open()
218
219             Dim OdAP As OleDbDataAdapter
220             OdAP = New OleDbDataAdapter(sql, OleDbConn)
221             OdAP.Fill(ds)
222             ListView3.Items.Clear()
223             ListView3.Columns.Clear()
224             ListView3.GridLines = True
225             ListView3.FullRowSelect = True
226             ListView3.HideSelection = False
227             ListView3.MultiSelect = False
228
229
230             ListView3.Columns.Add(ds.Tables(
0).Columns(0).Caption, 30, HorizontalAlignment.Left)
231             ListView3.Columns.Add(ds.Tables(
0).Columns(1).Caption, 90, HorizontalAlignment.Left)
232             ListView3.Columns.Add(ds.Tables(
0).Columns(2).Caption, 90, HorizontalAlignment.Left)
233             ListView3.Columns.Add(ds.Tables(
0).Columns(3).Caption, 90, HorizontalAlignment.Left)
234             ListView3.Columns.Add(ds.Tables(
0).Columns(4).Caption, 90, HorizontalAlignment.Left)
235             ListView3.Columns.Add(ds.Tables(
0).Columns(5).Caption, 90, HorizontalAlignment.Left)
236             ListView3.Columns.Add(ds.Tables(
0).Columns(6).Caption, 130, HorizontalAlignment.Left)
237
238             Dim i As Integer
239             Dim icol As Integer = ds.Tables(
0).Columns.Count
240             Dim k As Integer
241             Dim krow As Integer = ds.Tables(
0).Rows.Count
242             Dim thisrow(icol) As String
243             Dim j As Integer =
1
244             For k =
0 To krow - 1
245                 For i =
0 To icol - 1
246                     thisrow(i) = ds.Tables(
0).Rows(k).Item(i).ToString
247                 Next
248                 Dim lsvi As New ListViewItem(thisrow,
0)
249                 If k /
2 <> Int(k / 2) Then
250                     lsvi.BackColor = Color.Lavender
251                 Else
252                     lsvi.BackColor = Color.White
253                 End If
254                 j = j +
1
255                 ListView3.Items.Add(lsvi)
256
257             Next
258             ListView3.Sort()
259         Catch exc As Exception
260             MsgBox(exc.Message)
261
262         Finally
263             OleDbConn.Close()
264         End Try
265         
''''''''''''''''''FOR RESERVATION ''''''''''''''
266         Try
267             Dim sql As String
268             sql =
"SELECT * FROM List_of_Reserved"
269             Dim ds As DataSet
270             ds = New DataSet
271
272             OleDbConn.Open()
273
274             Dim OdAP As OleDbDataAdapter
275             OdAP = New OleDbDataAdapter(sql, OleDbConn)
276             OdAP.Fill(ds)
277             ListView4.Items.Clear()
278             ListView4.Columns.Clear()
279             ListView4.GridLines = True
280             ListView4.FullRowSelect = True
281             ListView4.HideSelection = False
282             ListView4.MultiSelect = False
283
284
285             ListView4.Columns.Add(ds.Tables(
0).Columns(0).Caption, 30, HorizontalAlignment.Left)
286             ListView4.Columns.Add(ds.Tables(
0).Columns(1).Caption, 90, HorizontalAlignment.Left)
287             ListView4.Columns.Add(ds.Tables(
0).Columns(2).Caption, 90, HorizontalAlignment.Left)
288             ListView4.Columns.Add(ds.Tables(
0).Columns(3).Caption, 90, HorizontalAlignment.Left)
289             ListView4.Columns.Add(ds.Tables(
0).Columns(4).Caption, 90, HorizontalAlignment.Left)
290             ListView4.Columns.Add(ds.Tables(
0).Columns(5).Caption, 90, HorizontalAlignment.Left)
291             ListView4.Columns.Add(ds.Tables(
0).Columns(6).Caption, 130, HorizontalAlignment.Left)
292
293             Dim i As Integer
294             Dim icol As Integer = ds.Tables(
0).Columns.Count
295             Dim k As Integer
296             Dim krow As Integer = ds.Tables(
0).Rows.Count
297             Dim thisrow(icol) As String
298             Dim j As Integer =
1
299             For k =
0 To krow - 1
300                 For i =
0 To icol - 1
301                     thisrow(i) = ds.Tables(
0).Rows(k).Item(i).ToString
302                 Next
303                 Dim lsvi As New ListViewItem(thisrow,
0)
304                 If k /
2 <> Int(k / 2) Then
305                     lsvi.BackColor = Color.Lavender
306                 Else
307                     lsvi.BackColor = Color.White
308                 End If
309                 j = j +
1
310                 ListView4.Items.Add(lsvi)
311
312             Next
313             ListView4.Sort()
314         Catch exc As Exception
315             MsgBox(exc.Message)
316
317         Finally
318             OleDbConn.Close()
319         End Try
320
321     End Sub
322     Private Sub ListView1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick
323         If ListView1.SelectedIndices.Count >
0 Then
324             Dim ItemNo As Integer = ListView1.SelectedIndices(
0)
325             Barrowing.Label12.Text = ListView1.Items(ItemNo).SubItems(
0).Text
326             Barrowing.TextBox3.Text = ListView1.Items(ItemNo).SubItems(
1).Text
327             Barrowing.Label10.Text = ListView1.Items(ItemNo).SubItems(
2).Text
328         Else
329         End If
330         Barrowing.ShowDialog()
331     End Sub
332
333     Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
334         Label7.Text = DateAndTime.Today
335     End Sub
336
337     Private Sub ListView2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView2.MouseClick
338         If ListView2.SelectedIndices.Count >
0 Then
339             Dim ItemNo As Integer = ListView2.SelectedIndices(
0)
340             Label9.Text = ListView2.Items(ItemNo).SubItems(
0).Text
341             TextBox1.Text = ListView2.Items(ItemNo).SubItems(
1).Text
342             TextBox2.Text = ListView2.Items(ItemNo).SubItems(
2).Text
343             TextBox3.Text = ListView2.Items(ItemNo).SubItems(
3).Text
344             TextBox4.Text = ListView2.Items(ItemNo).SubItems(
4).Text
345             TextBox5.Text = ListView2.Items(ItemNo).SubItems(
5).Text
346         Else
347         End If
348     End Sub
349
350     Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
351         OleDbConn.Open()
352         myCommand = New OleDbCommand(
"SELECT * FROM Item_list Where Name_of_Item LIKE '" & TextBox4.Text & "%'", OleDbConn)
353
354         MyReader = MyCommand.ExecuteReader()
355         While MyReader.Read
356             TextBox7.Text = MyReader(
"ID")
357             TextBox6.Text = MyReader(
"No_of_Item")
358         End While
359         OleDbConn.Close()
360         MyReader.Close()
361         MyCommand.dispose()
362     End Sub
363
364     Private Sub ListView4_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView4.MouseClick
365         If ListView4.SelectedIndices.Count >
0 Then
366             Dim ItemNo As Integer = ListView4.SelectedIndices(
0)
367             Label9.Text = ListView4.Items(ItemNo).SubItems(
0).Text
368             TextBox1.Text = ListView4.Items(ItemNo).SubItems(
1).Text
369             TextBox2.Text = ListView4.Items(ItemNo).SubItems(
2).Text
370             TextBox3.Text = ListView4.Items(ItemNo).SubItems(
3).Text
371             TextBox4.Text = ListView4.Items(ItemNo).SubItems(
4).Text
372             TextBox5.Text = ListView4.Items(ItemNo).SubItems(
5).Text
373         Else
374         End If
375     End Sub
376     Sub deleteforreserved()
377         Dim mss As String
378         If ListView4.SelectedIndices.Count <=
0 Then
379             Return
380         End If
381         Dim itemNo As Integer = ListView4.SelectedIndices(
0)
382         Try
383             mss = MsgBox(
"Are you sure you want to Barrowed this Item?", MsgBoxStyle.YesNo)
384
385             If mss = System.Windows.Forms.DialogResult.No Then
386                 MsgBox(
"Barrowed is Cancel", MsgBoxStyle.Information, "Barrowed Failed!")
387                 Exit Sub
388             Else
389                 Try
390                     OleDbConn.Open()
391                     Dim CMD2 As New OleDb.OleDbCommand(
"DELETE FROM List_of_Reserved WHERE ID=" & ListView4.Items(itemNo).SubItems(0).Text, OleDbConn)
392                     CMD2.ExecuteNonQuery()
393                     MsgBox(
"Items Successfully Barrowed")
394                 Catch ex As Exception
395                     MsgBox(ex.Message)
396                 End Try
397
398             End If
399
400         Catch ex As Exception
401             MsgBox(ex.Message)
402         Finally
403             OleDbConn.Close()
404         End Try
405         saveforbarrowed()
406         refreshing_utility()
407     End Sub
408     Sub saveforbarrowed()
409
410         Try
411
412             Dim OleDbConn As OleDbConnection = New OleDbConnection(ConnString)
413             OleDbConn.Open()
414
415             Dim MyOledbCommand As OleDbCommand = New OleDbCommand()
416
417             MyOledbCommand.CommandText =
"Insert Into List_of_Barrowed " & "(Name_of_Student_,Department_,Position_,Name_of_Items_,No_of_Items_,Date_Time_) " _
418             & 
"Values (" _
419             & 
"'" & TextBox1.Text & "', " _
420               & 
"'" & TextBox2.Text & "', " _
421                 & 
"'" & TextBox3.Text & "', " _
422                   & 
"'" & TextBox4.Text & "', " _
423                     & 
"'" & TextBox5.Text & "', " _
424                     & 
"'" & Label6.Text & ", " & Label7.Text & "')"
425
426             MyOledbCommand.Connection = OleDbConn
427             MyOledbCommand.ExecuteNonQuery()
428             OleDbConn.Close()
429             MsgBox(
"Items Successfully Barrowed")
430
431         Catch err As System.Exception
432             MsgBox(err, MsgBoxStyle.Information,
"Naay Sayup")
433         End Try
434         refreshing_utility()
435     End Sub
436
437     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
438         deleteforreserved()
439         savealltrans()
440     End Sub
441
442
443     Private Sub ListView4_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView4.SelectedIndexChanged
444         If ListView4.SelectedIndices.Count >
0 Then
445             Dim ItemNo As Integer = ListView4.SelectedIndices(
0)
446             TextBox4.Text = ListView4.Items(ItemNo).SubItems(
4).Text
447             TextBox5.Text = ListView4.Items(ItemNo).SubItems(
5).Text
448         Else
449         End If
450     End Sub
451
452     Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
453         TextBox8.Text = TextBox6.Text + +TextBox5.Text
454     End Sub
455
456     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
457         deleteforreserved()
458         editing()
459         refreshing_utility()
460     End Sub
461
462     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
463         refreshing_utility()
464     End Sub
465     Sub savealltrans()
466         Try
467
468             Dim OleDbConn As OleDbConnection = New OleDbConnection(ConnString)
469             OleDbConn.Open()
470
471             Dim MyOledbCommand As OleDbCommand = New OleDbCommand()
472             Dim itemNo As Integer = ListView2.SelectedIndices(
0)
473             MyOledbCommand.CommandText =
"Insert Into All_Transaction " & "(Name_of_Student_,Department_,Position_,Name_of_Items_,No_of_Items_,Date_Time_,Remarks_) " _
474             & 
"Values (" _
475             & 
"'" & TextBox1.Text & "', " _
476               & 
"'" & TextBox2.Text & "', " _
477                 & 
"'" & TextBox3.Text & "', " _
478                   & 
"'" & TextBox4.Text & "', " _
479                     & 
"'" & TextBox5.Text & "', " _
480                       & 
"'" & Label6.Text & ", " & Label7.Text & "', " _
481                     & 
"'" & "OK" & "')"
482
483             MyOledbCommand.Connection = OleDbConn
484             MyOledbCommand.ExecuteNonQuery()
485             OleDbConn.Close()
486
487         Catch err As System.Exception
488
489         End Try
490         refreshing_utility()
491     End Sub
492
493     Private Sub TextBox9_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox9.TextChanged
494         Try
495             Dim sql As String
496             sql =
"SELECT * FROM List_of_Returned Where Name_of_Items_ LIKE '" & TextBox9.Text & "%'"
497             Dim ds As DataSet
498             ds = New DataSet
499
500             OleDbConn.Open()
501
502             Dim OdAP As OleDbDataAdapter
503             OdAP = New OleDbDataAdapter(sql, OleDbConn)
504             OdAP.Fill(ds)
505             ListView3.Items.Clear()
506             ListView3.Columns.Clear()
507             ListView3.GridLines = True
508             ListView3.FullRowSelect = True
509             ListView3.HideSelection = False
510             ListView3.MultiSelect = False
511
512             For aw As Integer =
0 To ds.Tables(0).Columns.Count - 1
513                 ListView3.Columns.Add(ds.Tables(
0).Columns(aw).Caption, 85, HorizontalAlignment.Left)
514             Next
515             Dim i As Integer
516             Dim icol As Integer = ds.Tables(
0).Columns.Count
517             Dim k As Integer
518             Dim krow As Integer = ds.Tables(
0).Rows.Count
519             Dim thisrow(icol) As String
520             Dim j As Integer =
1
521             For k =
0 To krow - 1
522                 For i =
0 To icol - 1
523                     thisrow(i) = ds.Tables(
0).Rows(k).Item(i).ToString
524                 Next
525                 Dim lsvi As New ListViewItem(thisrow,
0)
526                 If k /
2 <> Int(k / 2) Then
527                     lsvi.BackColor = Color.Lavender
528                 Else
529                     lsvi.BackColor = Color.White
530                 End If
531                 j = j +
1
532                 ListView3.Items.Add(lsvi)
533
534             Next
535             ListView3.Sort()
536         Catch exc As Exception
537             MsgBox(exc.Message)
538
539         Finally
540             OleDbConn.Close()
541         End Try
542     End Sub
543
544     Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
545         Dim Con As New OleDbConnection(
"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=CLInventory.accdb; Persist Security Info=False")
546         Dim Ans As String
547         Ans = MsgBox(
"Are you sure to Delete the selected record?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Are you sure to delete?")
548         Dim itemNo As Integer = ListView1.SelectedIndices(
0)
549         If Ans = System.Windows.Forms.DialogResult.No Then
550             MsgBox(
"Deletion opereation is aborted by user.", MsgBoxStyle.Information, "Record nor deleted.")
551
552             Exit Sub
553         Else
554             Try
555                 Dim com As New OleDbCommand
556                 com.Connection = Con
557                 Con.Open()
558                 com.CommandText =
"delete from Item_list where ID=" & ListView1.Items(itemNo).SubItems(0).Text
559                 com.ExecuteNonQuery()
560                 MsgBox(
"Selected record has been Deleted.", MsgBoxStyle.Information, "Record Deleted")
561                 Con.Close()
562               
563             Catch exp As Exception
564                 MsgBox(exp.ToString())
565             End Try
566             refreshing_utility()
567
568         End If
569     End Sub
570
571     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
572         If ListView1.SelectedIndices.Count >
0 Then
573             Dim ItemNo As Integer = ListView1.SelectedIndices(
0)
574             Updatesss.Label1.Text = ListView1.Items(ItemNo).SubItems(
0).Text
575             Updatesss.TextBox1.Text = ListView1.Items(ItemNo).SubItems(
1).Text
576             Updatesss.TextBox2.Text = ListView1.Items(ItemNo).SubItems(
2).Text
577         Else
578         End If
579         Updatesss.ShowDialog()
580     End Sub
581
582     Private Sub TextBox10_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox10.TextChanged
583         Try
584             Dim sql As String
585             sql =
"SELECT * FROM List_of_Returned Where Date_Time_ LIKE '%" & TextBox10.Text & "%'"
586             Dim ds As DataSet
587             ds = New DataSet
588
589             OleDbConn.Open()
590
591             Dim OdAP As OleDbDataAdapter
592             OdAP = New OleDbDataAdapter(sql, OleDbConn)
593             OdAP.Fill(ds)
594             ListView3.Items.Clear()
595             ListView3.Columns.Clear()
596             ListView3.GridLines = True
597             ListView3.FullRowSelect = True
598             ListView3.HideSelection = False
599             ListView3.MultiSelect = False
600
601             For aw As Integer =
0 To ds.Tables(0).Columns.Count - 1
602                 ListView3.Columns.Add(ds.Tables(
0).Columns(aw).Caption, 85, HorizontalAlignment.Left)
603             Next
604             Dim i As Integer
605             Dim icol As Integer = ds.Tables(
0).Columns.Count
606             Dim k As Integer
607             Dim krow As Integer = ds.Tables(
0).Rows.Count
608             Dim thisrow(icol) As String
609             Dim j As Integer =
1
610             For k =
0 To krow - 1
611                 For i =
0 To icol - 1
612                     thisrow(i) = ds.Tables(
0).Rows(k).Item(i).ToString
613                 Next
614                 Dim lsvi As New ListViewItem(thisrow,
0)
615                 If k /
2 <> Int(k / 2) Then
616                     lsvi.BackColor = Color.Lavender
617                 Else
618                     lsvi.BackColor = Color.White
619                 End If
620                 j = j +
1
621                 ListView3.Items.Add(lsvi)
622
623             Next
624             ListView3.Sort()
625         Catch exc As Exception
626             MsgBox(exc.Message)
627
628         Finally
629             OleDbConn.Close()
630         End Try
631     End Sub
632
633     Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
634          deletePrint()
635         printttt()
636
637     End Sub
638     
'===========================
639     Sub printttt()
640         Try
641             Dim sql As String
642             sql =
"SELECT * FROM List_of_Returned WHERE Date_Time_ LIKE '%" & TextBox10.Text & "%'"
643             Dim ds As DataSet
644             ds = New DataSet
645
646             OleDbConn.Open()
647
648             Dim OdAP As OleDbDataAdapter
649             OdAP = New OleDbDataAdapter(sql, OleDbConn)
650             OdAP.Fill(ds)
651             Dim i As Integer
652             Dim icol As Integer = ds.Tables(
0).Columns.Count
653             Dim k As Integer
654             Dim krow As Integer = ds.Tables(
0).Rows.Count
655             Dim thisrow(icol) As String
656             Dim j As Integer =
1
657             For k =
0 To krow - 1
658                 For i =
0 To icol - 1
659                     thisrow(i) = ds.Tables(
0).Rows(k).Item(i).ToString
660                     str1 = thisrow(
1)
661                     str2 = thisrow(
2)
662                     str3 = thisrow(
3)
663                     str4 = thisrow(
4)
664                     str5 = thisrow(
5)
665                     str6 = thisrow(
6)
666                 Next
667                 savePrint()
668             Next
669         Catch exc As Exception
670             MsgBox(exc.Message)
671
672         Finally
673             OleDbConn.Close()
674         End Try
675         Printing.ShowDialog()
676     End Sub
677     Sub savePrint()
678         Dim oAdapter As OleDb.OleDbDataAdapter
679         Dim cb As OleDb.OleDbCommandBuilder
680         Dim dr As DataRow
681         Dim ds As DataSet
682         Dim strSQL As String =
"SELECT * FROM List_of_Returned_print"
683
684         ds = New DataSet()
685         oAdapter = New OleDb.OleDbDataAdapter(strSQL, OleDbConn)
686         oAdapter.Fill(ds)
687         Try
688             dr = ds.Tables(
0).NewRow()
689             dr.BeginEdit()
690
691             dr(
"Name_of_Student_") = str1
692             dr(
"Department_") = str2
693             dr(
"Position_") = str3
694             dr(
"Name_of_Items_") = str4
695             dr(
"No_of_Items_") = str5
696             dr(
"Date_Time_") = str6
697           
698             dr.EndEdit()
699
700             ds.Tables(
0).Rows.Add(dr)
701             cb = New OleDb.OleDbCommandBuilder(oAdapter)
702             oAdapter.InsertCommand = cb.GetInsertCommand
703             oAdapter.Update(ds)
704             ds.AcceptChanges()
705         Catch ex As Exception
706             MessageBox.Show(ex.Message)
707         Finally
708             OleDbConn.Close()
709         End Try
710     End Sub
711     Sub deletePrint()
712         Try
713             Dim com As New OleDbCommand
714             com.Connection = OleDbConn
715             OleDbConn.Open()
716             com.CommandText =
"delete from List_of_Returned_print where ID>=" & (0)
717             com.ExecuteNonQuery()
718             OleDbConn.Close()
719         Catch exp As Exception
720             MsgBox(exp.ToString())
721         End Try
722     End Sub
723 End Class


Gõ tìm kiếm nhanh...